package com.aglhz.nature.adapter;

import java.util.List;




import com.aglhz.nature.R;
import com.aglhz.nature.modle.item.ColumnsListData;
import com.aglhz.nature.view.AroundActivity;
import com.aglhz.nature.view.HomeShowWebActivity;
import com.aglhz.nature.view.LoginActivity;
import com.aglhz.nature.view.NatureLifeWebActivity;
import com.aglhz.nature.view.SeasonalRecommendWebActivity;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ColumnsListAdapter extends BaseAdapter{
	private LayoutInflater inflater;
	public List<ColumnsListData> mData;
    public Context context; 
    
    
	public ColumnsListAdapter(List<ColumnsListData> data, Context context) {
		super();
		this.mData = data;
		this.context = context;
	}

	@Override
	public int getCount() {
	
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
	
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
	
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		 ViewHolder viewHolder; 
		if(null==convertView){			
			  convertView = LayoutInflater.from(context).inflate(R.layout.item_columnslist, null); 
			  viewHolder = new ViewHolder();
			  viewHolder.image = (ImageView) convertView.findViewById(R.id.iv_classification); 
			  viewHolder.name = (TextView) convertView.findViewById(R.id.tv_classification); 
			  
			  convertView.setTag(viewHolder); 
		}else{
			viewHolder = (ViewHolder) convertView.getTag(); 
		}
		//设置图片		
			  String imgUrl = mData.get(position).getPicture();
			//picasso加载网络图片
			   Picasso.with(context)  
			   .load(imgUrl)  	    	               
			   .into(viewHolder.image) ;
		  
		//设置名字
		viewHolder.name.setText(mData.get(position).getTitle());
		int height= viewHolder.name.getLayoutParams().height;
		int screenWidth = getScreenWidth();
		GridView.LayoutParams p=new GridView.LayoutParams(screenWidth/5,height+screenWidth/5);
		convertView.setLayoutParams(p);
		
		
		 viewHolder.image.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					Log.e("ssssssssss", mData.get(position).getId());
					if(mData.get(position).getId().equals("6f7bda56-f608-4efb-b9d7-f19f77d82864")){
						//周边
						Log.e("ssssssssss", "---------------"+mData.get(position).getId());
						Intent intent=new Intent(context,AroundActivity.class);
						context.startActivity(intent);
					}else if(mData.get(position).getId().equals("da2d8fc0-1f14-4a8c-9712-41a7191e7edb")){
						//登陆
						Log.e("sssddddssss", "---------------"+mData.get(position).getId());
						Intent intent=new Intent(context,LoginActivity.class);
						context.startActivity(intent);
					} else if(mData.get(position).getId().equals("091282e7-aa56-4847-8307-74c0cabce827")){
						//应季推荐
						Log.e("sssseeeeeessss", "---------------"+mData.get(position).getId());
						Intent intent=new Intent(context,SeasonalRecommendWebActivity.class);
						intent.putExtra("SeasonalRecommendWebActivity",mData.get(position).getLink());
						context.startActivity(intent);
					}else if(mData.get(position).getId().equals("114ac6a4-1ccb-4498-b4e3-6d8bb8b4c720")){
						//自然生活
						Intent intent=new Intent(context,NatureLifeWebActivity.class);
						intent.putExtra("NatureLifeWebActivity",mData.get(position).getLink());
						context.startActivity(intent);
						
					}else{
						//秀场
						Intent intent=new Intent(context,HomeShowWebActivity.class);
						intent.putExtra("HomeShowWebActivity",mData.get(position).getLink());
						context.startActivity(intent);
					}
				}
			});
		return convertView;
	}
	class ViewHolder 
	{  
	    public ImageView image; 
	    public TextView name;
	} 
	
	/**
	 * 获取屏幕宽度
	 * 
	 * @return
	 */
	protected int getScreenWidth() {
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		return display.getWidth();
	}

}
